<template>
	<div class="page">微信openid：{{ wxOpenid }}</div>
</template>

<script setup name="WxLogin">
	import wxAuth from '@/api/wx/wxAuth.js'
	import { useRouter } from 'vue-router'
	import { ref, onMounted } from 'vue'

	const router = useRouter()
	const wxOpenid = ref(null)
	//方法一：从服务端获取URL
	//onMounted(() => {
	//     let currentUrl = encodeURIComponent('http://www.dgpms.cn/hik/wx/wxauth') //window.location.href)
	//     service
	//         .get('/api/wechat/authPage')
	//         .then((res) => {
	//             if (res.code == 200) {
	//                 console.log("the url is :"+res.data)
	//                 window.location.href = res.data
	//             }
	//         })
	//      })

	//方法二：自己拼接URL
	onMounted(() => {
		wxAuth().then((openid) => {
			wxOpenid.value = openid
			console.log('用户现在已授权完成，openId为：===>>' + openid)
			router.push('wxfirstauth')
		})
		//this.$wxShare();
	})
</script>

<style scoped>
	.page {
		background-color: #f0f3f5;
	}
</style>
